package net.sppan.blog.controller.front;

import javax.annotation.Resource;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import net.sppan.blog.entity.Check;
import net.sppan.blog.service.CheckService;

@Controller
@RequestMapping("/c")
public class CheckController {
	@Resource
	private CheckService checkService;

	@RequestMapping("/list")
	public String index(@RequestParam(required = false, defaultValue = "1") Integer p, ModelMap map) {
		PageRequest pageRequest = new PageRequest(p - 1, 1);
		Page<Check> page = checkService.findPrivacy(0, pageRequest);
		map.put("page", page);
		return "front/check/index";
	}

	@RequestMapping("/view/{id}")
	public String view(@PathVariable("id") Long id, @RequestParam(required = false) Integer success, ModelMap map) {
		Check check = checkService.findById(id);
		map.put("check", check);
		return "front/check/detail";
	}
}
